package com.wondersgroup.framework.widget.taglib.form;

import com.wondersgroup.framework.widget.annotations.WidgetTag;
import com.wondersgroup.framework.widget.annotations.WidgetTagAttribute;
import com.wondersgroup.framework.widget.context.DefaultSettings;
import com.wondersgroup.framework.widget.library.extjs.ExtComponent;
import com.wondersgroup.framework.widget.library.extjs.form.ExtDateTimeField;
import com.wondersgroup.framework.widget.library.html.Div;
import com.wondersgroup.framework.widget.library.html.HtmlComponent;
import com.wondersgroup.framework.widget.taglib.form.util.FormUtils;
import com.wondersgroup.framework.widget.util.OutputUtils;
import com.wondersgroup.framework.widget.util.TagUtils;
import com.wondersgroup.framework.widget.validation.annotation.TagValidate;
import javax.servlet.jsp.JspException;
import org.springframework.beans.BeanUtils;

@TagValidate
@WidgetTag(name = "dateTimeField", tldTagClass = "com.wondersgroup.framework.widget.taglib.form.DateTimeFieldTag", description = "dateTimeField会同时出现两个控件，一个日期控件一个时间控件，可以使用户把时间定义到分钟")
public class DateTimeFieldTag extends BaseDateFieldTag {
	private String dateFormat = DefaultSettings.get("widget.format.date");
	private String timeFormat = DefaultSettings.get("widget.format.time");
	private String dateWidth = "140";
	private String timeWidth = "100";

	public void processStartTagContent() throws JspException {
		Div localDiv = new Div(getId() + "_div");
		ExtDateTimeField localExtDateTimeField = new ExtDateTimeField(getId());
		BeanUtils.copyProperties(this, localExtDateTimeField);
		localExtDateTimeField.setWidth(String.valueOf((Integer.parseInt(getDateWidth()) + Integer.parseInt(getTimeWidth()) + 23)));
		localExtDateTimeField.setFormItems(getFormItems());
		if ((getToolBarArray() == null) && (getStatusBarArray() == null)) {
			localExtDateTimeField.setRenderTo(localDiv.getId());
		}
			
		StringBuffer localStringBuffer = new StringBuffer();
		localStringBuffer.append(OutputUtils.writeHTML(new HtmlComponent[] { localDiv }));
		localStringBuffer.append(OutputUtils.writeJSFile(this.pageContext, new String[] { "wonders/form/wonders-form-min.js" }));
		localStringBuffer.append(OutputUtils.ExtOnReady(new ExtComponent[] { localExtDateTimeField }));
		if (!(TagUtils.inGridColumn(this.pageContext, localExtDateTimeField))) {
			FormUtils.addFieldsToForm(this.pageContext, localExtDateTimeField);
			TagUtils.getInstance().write(this.pageContext, localStringBuffer.toString());
		}
	}

	public String getDateFormat() {
		return this.dateFormat;
	}

	@WidgetTagAttribute(description = "日期格式 默认为配置文件中的widget.format.date值", required = false)
	public void setDateFormat(String paramString) {
		this.dateFormat = paramString;
	}

	public String getTimeFormat() {
		return this.timeFormat;
	}

	@WidgetTagAttribute(description = "时间格式 默认为配置文件中的widget.format.time值", required = false)
	public void setTimeFormat(String paramString) {
		this.timeFormat = paramString;
	}

	public String getDateWidth() {
		return this.dateWidth;
	}

	@WidgetTagAttribute(description = "日期框宽度 默认为160", required = false)
	public void setDateWidth(String paramInt) {
		this.dateWidth = paramInt;
	}

	public String getTimeWidth() {
		return this.timeWidth;
	}

	@WidgetTagAttribute(description = "时间框宽度 默认为160", required = false)
	public void setTimeWidth(String paramInt) {
		this.timeWidth = paramInt;
	}
}